Skip to content

fix: errors related to unavailable Snap keyring#8196

Open
david0xd wants to merge 12 commits intomainfrom
dd/fix-snap-keyring-errors
Open

fix: errors related to unavailable Snap keyring#8196
david0xd wants to merge 12 commits intomainfrom
dd/fix-snap-keyring-errors

Conversation

@david0xd
Copy link
Contributor

@david0xd david0xd commented Mar 12, 2026

Explanation

This PR adds a fix for errors appearing in the background console when Snap keyring is not yet available. Waiting mechanism is added for the Snap keyring to become available and ready for use.

References

Fixes: MetaMask/metamask-extension#40543

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Adds new waiting/timeout logic around Snap platform readiness and Snap keyring availability, which can affect non-EVM account creation timing and introduce new timeout failure modes if misconfigured.

Overview
Fixes non-EVM account creation failures after wallet reset/restore by extending SnapPlatformWatcher.ensureCanUseSnapPlatform() to also wait for the Snap keyring to exist (via KeyringController:getState and KeyringController:stateChange) before proceeding, with explicit timeout errors.

Introduces configurable watcher timeouts (config.snapWatcher.timeoutMs) and adds tests/mocks (including MOCK_SNAP_KEYRING) covering keyring-appearance, getState-error, and timeout scenarios; updates changelog accordingly.

Written by Cursor Bugbot for commit a336710. This will update automatically on new commits. Configure here.

@david0xd david0xd self-assigned this Mar 12, 2026
Comment on lines +86 to +91
const keyrings = this.#messenger.call(
'KeyringController:getKeyringsByType',
KeyringTypes.snap,
);

return Array.isArray(keyrings) && keyrings.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just use the KeyringController's state directly like with :getState. So the logic between this method and #waitForSnapKeyringViaStateChange would be pretty similar.

The other reason is because :getKeyringsByType is "deprecated" (even though we're still using it all over the place yes 🙃)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored it now to use getState.

@david0xd david0xd force-pushed the dd/fix-snap-keyring-errors branch from cd583e6 to a406552 Compare March 16, 2026 15:17
@david0xd david0xd marked this pull request as ready for review March 16, 2026 15:17
@david0xd david0xd requested a review from a team as a code owner March 16, 2026 15:17
@david0xd david0xd requested a review from a team as a code owner March 16, 2026 16:30
@david0xd david0xd force-pushed the dd/fix-snap-keyring-errors branch from f0f219a to ddb6c65 Compare March 17, 2026 11:00
@david0xd david0xd force-pushed the dd/fix-snap-keyring-errors branch from ddb6c65 to 020aa05 Compare March 17, 2026 11:13
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Reset Wallet - Throws multiple errors related to accounts and keyring operations

3 participants